<template>
	<view class="vertical-center">
		<view class="header">
			<!-- 左侧用户信息区域 -->
			<view class="left-section">
				<image class="avatar" src="/static/logo.png"></image>
				<view class="user-info">
					<template v-if="isLogin">
						<text class="username">{{userInfo.nickname}}</text>
						<text class="description"
							@click="goto(`/uni_modules/uni-id-pages/pages/userinfo/userinfo?showLoginManage=true`)">个人主页></text>
					</template>
					<text v-else class="login-text"
						@click="goto(`/uni_modules/uni-id-pages/pages/login/login-withpwd?type=weixin`)">去登录</text>
				</view>
			</view>

			<!-- 右侧按钮 -->
			<view class="buttons">
				<button class="btn" @click="handleContact">联系客服</button>
				<button class="btn" @click="handleSettings">
					设置<image class="settings-icon" src="/static/logo.png"></image>
				</button>
			</view>
		</view>
		<view style="width: 100%;height: 50rpx;text-align: center;" @click="toPublish">去发布</view>

		<!-- 四个功能按钮 -->
		<view class="function-buttons">
			<view class="function-item" @click="handleFunction(1)">
				<image class="function-icon" src="/static/logo.png"></image>
				<text class="function-text">我的发布</text>
			</view>
			<view class="function-item" @click="handleFunction(2)">
				<image class="function-icon" src="/static/logo.png"></image>
				<text class="function-text">功能二</text>
			</view>
			<view class="function-item" @click="handleFunction(3)">
				<image class="function-icon" src="/static/logo.png"></image>
				<text class="function-text">功能三</text>
			</view>
			<view class="function-item" @click="handleFunction(4)">
				<image class="function-icon" src="/static/logo.png"></image>
				<text class="function-text">功能四</text>
			</view>
		</view>

	</view>
</template>

<script>
	import {
		store,
		mutations
	} from '@/uni_modules/uni-id-pages/common/store.js'
	export default {
		computed: {
			userInfo() {
				return store.userInfo
			}
		},
		data() {
			return {
				userName: "",
				isLogin: false,
			}
		},
		methods: {
			onLoad() {

			},
			onShow() {
				if (this.userInfo._id) {
					this.isLogin = true;
				} else {
					this.isLogin = false;
				}
			},
			handleSettings() {
				// 处理设置按钮点击
			},
			handleContact() {
				// 处理联系客服点击
			},
			handleFunction(index) {
				if(index == 1) {
					this.toMyPublish()
				}
			},
			goto(url) {
				// 实现跳转到登录页面的逻辑
				uni.navigateTo({
					"url": url
				})
			},

			toMyPublish() {
				uni.navigateTo({
					"url": '/pages/tabBar/publish/myPublish'
				})
			},
			toPublish() {
				uni.navigateTo({
					"url": '/pages/tabBar/publish/publish'
				})
			},
			async toTestProMe() {
				const res = await uniCloud.callFunction({
					name: 'page-main',
					data: {
						username: 'kuku',
						age: 29
					}
				})
			}

		}
	}
</script>

<style>
	.vertical-center {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}


	.header {
		display: flex;
		align-items: center;
		padding: 20rpx;
		background-color: #ffffff;
	}

	.left-section {
		flex: 1;
		display: flex;
		align-items: center;
	}

	.avatar {
		width: 120rpx;
		height: 120rpx;
		border-radius: 60rpx;
	}

	.user-info {
		flex: 1;
		margin-left: 20rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
	}

	.username {
		font-size: 32rpx;
		font-weight: bold;
		display: block;
	}

	.description {
		font-size: 28rpx;
		color: #666;
		margin-top: 10rpx;
		display: block;
	}

	.login-text {
		font-size: 32rpx;
		color: #666;
	}

	.buttons {
		display: flex;
		align-items: center;
	}

	.btn {
		margin: 0 10rpx;
		padding: 0 20rpx;
		height: 60rpx;
		line-height: 60rpx;
		font-size: 28rpx;
		background: #f5f5f5;
		border: none;
	}

	.settings-icon {
		width: 40rpx;
		height: 40rpx;
	}

	.function-buttons {
		display: flex;
		justify-content: space-around;
		width: 100%;
		padding: 30rpx 20rpx;
		background-color: #ffffff;
		margin-top: 20rpx;
	}

	.function-item {
		display: flex;
		flex-direction: column;
		align-items: center;
		width: 25%;
	}

	.function-icon {
		width: 80rpx;
		height: 80rpx;
		margin-bottom: 10rpx;
	}

	.function-text {
		font-size: 24rpx;
		color: #333;
	}
</style>